|
Eclipse Platform Pre-release 3.0 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.jface.text.formatter.ContentFormatter2
Improved standard implementation of IContentFormatter
. The formatter
supports three operation modi: partition aware, partition unaware and
context based.
In the partition aware mode, the formatter determines the partitioning of the document region to be formatted. For each partition it determines all document positions which are affected when text changes are applied to the partition. Those which overlap with the partition are remembered as character positions. These character positions are passed over to the formatting strategy registered for the partition's content type. The formatting strategy returns a string containing the formatted document partition as well as the adapted character positions. The formatted partition replaces the old content of the partition. The remembered document postions are updated with the adapted character positions. In addition, all other document positions are accordingly adapted to the formatting changes.
In the partition unaware mode, the document's partitioning is ignored and
the document is considered consisting of only one partition of the content
type IDocument.DEFAULT_CONTENT_TYPE
. The formatting process
is similar to the partition aware mode, with the exception of having only
one partition.
The context based mode is supported by the extension interface IContentFormatterExtension2
and supersedes the previous modes. Clients using context based formatting
call the method format(IDocument, IFormattingContext)
with a
properly initialized formatting context.
The formatting context must be
set up according to the desired formatting mode:
CONTEXT_DOCUMENT
.
CONTEXT_PARTITION
.
CONTEXT_REGION
.
CONTEXT_PREFERENCES
.
Note that in context based mode the content formatter is fully reentrant,
but not thread-safe. Formatting strategies are therefore allowed to
recursively call the method format(IDocument, IFormattingContext)
.
The formatting context is saved between calls to this method.
Usually, clients instantiate this class and configure it before using it.
IContentFormatter
,
IContentFormatterExtension2
,
IDocument
,
ITypedRegion
,
Position
Constructor Summary | |
ContentFormatter2()
Creates a new content formatter. |
Method Summary | |
void |
enablePartitionAwareFormatting(boolean enable)
Sets whether the formatter operates in partition aware mode. |
void |
format(IDocument document,
IFormattingContext context)
Formats the given region of the specified document. |
void |
format(IDocument document,
IRegion region)
Formats the given region of the specified document.The formatter may safely assume that it is the only subject that modifies the document at this point in time. |
String |
getDocumentPartitioning()
Returns the partitioning this content formatter is using. |
IFormattingStrategy |
getFormattingStrategy(String contentType)
Returns the formatting strategy registered for the given content type. |
protected boolean |
positionAboutToBeAdded(IDocument document,
String category,
Position position)
The given position is about to be added to the given position category of the given document. |
void |
setDocumentPartitioning(String partitioning)
Sets the document partitioning to be used by this formatter. |
void |
setFormattingStrategy(IFormattingStrategy strategy)
Registers the master strategy for this content formatter. |
void |
setFormattingStrategy(IFormattingStrategy strategy,
String type)
Registers a slave strategy for a particular content type. |
void |
setPartitionManagingPositionCategories(String[] categories)
Deprecated. incompatible with an open set of document partitionings. The provided information is only used if this formatter can not compute the partition managing position categories. |
protected void |
updateAffectedPositions(IDocument document,
int[] positions,
int offset)
Updates all the overlapping positions. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ContentFormatter2()
The content formatter operates by default in the partition-aware mode.
There are no preconfigured formatting strategies. It will use the
default document partitioning if not further configured. The context
based mode is enabled by calls to format(IDocument, IFormattingContext
.
Method Detail |
public void setPartitionManagingPositionCategories(String[] categories)
categories
- the categories to be ignoredpublic void setDocumentPartitioning(String partitioning)
partitioning
- the document partitioningpublic String getDocumentPartitioning()
IContentFormatterExtension
getDocumentPartitioning
in interface IContentFormatterExtension
public void enablePartitionAwareFormatting(boolean enable)
enable
- true
iff partition aware mode should be
enabled, false
otherwise.public IFormattingStrategy getFormattingStrategy(String contentType)
IContentFormatter
getFormattingStrategy
in interface IContentFormatter
contentType
- the content type for which to look up the formatting strategy
null
if there is no such strategypublic void format(IDocument document, IRegion region)
IContentFormatter
format
in interface IContentFormatter
document
- the document to be formattedregion
- the region within the document to be formattedpublic void format(IDocument document, IFormattingContext context)
IContentFormatterExtension2
The formatter may safely assume that it is the only subject that
modifies the document at this point in time. This method is fully
reentrant. Formatting strategies registered with IContentFormatterExtension2
objects are therefore allowed to recursively call this method on
subregions of the region to be formatted.
The formatting process performed by format(IDocument, IFormattingContext)
happens as follows:
format
in interface IContentFormatterExtension2
document
- The document to be formattedcontext
- The formatting context to pass to the formatting strategies.
This argument must not be null
. Most
formatting strategies only require the CONTEXT_DOCUMENT
to be set. Depending on the registered formatting strategies,
more properties can be required.public void setFormattingStrategy(IFormattingStrategy strategy, String type)
If there is already a slave strategy registered for this type, the new
strategy is registered instead of the old one. The content type type
must be a valid content type of the registered partitioning of the
formatter.
Note that slave strategies can only be registered if a master strategy has been registered before.
strategy
- The formatting strategy to register as a slave strategy, or
null
to remove an existing onetype
- The content type under which to register the slave strategypublic void setFormattingStrategy(IFormattingStrategy strategy)
Note that slave strategies can only be registered if a master strategy has been registered before.
strategy
- The formatting strategy to register as the master strategy, or
null
to remove the existing oneprotected void updateAffectedPositions(IDocument document, int[] positions, int offset)
document
- the document to has been formattedpositions
- the adapted character positions to be used to update the document positionsoffset
- the offset of the document region that has been formattedprotected boolean positionAboutToBeAdded(IDocument document, String category, Position position)
This default implementation enacts the same rule as the TextViewer, i.e. if the position is used for managing slave documents it is ensured that the slave document starts at a line offset.
document
- the documentcategory
- the position categroyposition
- the position that will be added
true
if the position can be added, false
if it should be ignored
|
Eclipse Platform Pre-release 3.0 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |